package nc.tb.util.ui;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class SwingWokerTest {
	private static int nimgs = 10;
	private static ImageIcon[] imgs = null;
	private static JPanel animator = new JPanel();
	
	
	public static void main(String[] args){
		try {
			
			SwingWorker worker = new SwingWorker() {
				private ImageIcon laodImage(int k){
					for(int i = 0; i< Integer.MAX_VALUE; i ++){
						
					}
					return new ImageIcon("");
				}
			    /*@Override*/
			    public Object construct() {
			        final ImageIcon[] innerImgs = new ImageIcon[nimgs];
			        for (int i = 0; i < nimgs; i++) {
			            innerImgs[i] = laodImage(i+1);
			        }
			        return innerImgs;
			    }

			    /*@Override*/
			    public void finished() {
			        //Remove the "Loading images" label.
			        animator.removeAll();
//			        loopslot = -1;
			        try {
			            imgs = (ImageIcon[])get();
			        } catch (Exception ignore) {}
			        /*catch (java.util.concurrent.ExecutionException e) {
			            String why = null;
			            Throwable cause = e.getCause();
			            if (cause != null) {
			                why = cause.getMessage();
			            } else {
			                why = e.getMessage();
			            }
			            System.err.println("Error retrieving file: " + why);
			        }*/
			    }
			};
			worker.start();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}
